# OTableau : WYSIWYG editor for OT tableaux, generating LaTeX code
# Copyright (C) 2006 Julien Eychenne
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
# MA  02110-1301, USA.

from ConfigParser import ConfigParser
import sys, os

#accelerator
if sys.platform == 'darwin': 
    acc  = 'Command'
    bAcc = 'Command-Key' # bindings
    helpAcc  = '?'
    helpBAcc = '?'
else: 
    acc  = 'Ctrl'
    bAcc = 'Control'
    helpAcc  = 'H'
    helpBAcc = 'h'

defaultParams = {
    'unix_pdf_viewer' : 'acroread',
    'check_acrobat' : 'yes',
    # this must be either 'None' or 'RIDGE'
    'mac_cell_relief' : 'None',
    'angle' : '90',
    'ipa' : 'textipa',
    'hand' : 'ding{43}',
    'color' : 'lightgray'
}

#userDir = os.environ.get('HOME')

def parseParameters(fileObject):
    pars = {}
    parser = ConfigParser()
    parser.readfp(fileObject)
    for section in parser.sections():
        for option in parser.options(section):
            pars[option] = parser.get(section, option)
    return pars


def readParameters(file='settings.ini'):
    params = {}
    try:
        settingFile = open(file, 'r')
        params = parseParameters(settingFile)
    except IOError:
        if sys.platform == 'darwin':
            try:
                settingFile = open('$HOME/Library/Preferences/otableau-settings.ini')
            except IOError:
                os.system('cp settings.osx $HOME/Library/Preferences/otableau-settings.ini')
                settingFile = open(os.environ["HOME"] + '/Library/Preferences/otableau-settings.ini')
            params = parseParameters(settingFile)
    except:
        params = defaultParams
    return params


if __name__ == '__main__':
    params = {}
    
    params = readParameters()
    
    for key in params.keys():
        print "%s === %s" % (key, params[key])
